package com.zhny.sensor.usms;

import com.zhny.sensor.utils.ByteUtils;
import org.junit.Test;

import java.util.Arrays;

public class demo {
    @Test
    public void test(){
        String str = "MJUsVhJZ2NGuHSKJ";

        System.out.println(stringToHexStr(str));

        byte[] bytes = HexStrToByteArray(str);
        System.out.println(bytes[0]);
    }
    public String stringToHexStr(String str){
        char[] chars = "0123456789ABCDEF".toCharArray();
        StringBuilder builder = new StringBuilder("");
        byte[] bs = str.getBytes();
        int bit;
        for (int i = 0; i < bs.length; i++) {
            bit = (bs[i] & 0x0f0) >> 4;
            builder.append(chars[bit]);
            bit = bs[i] & 0x0f;
            builder.append(chars[bit]);
        }
        return builder.toString().trim();
    }

    public static byte[] HexStrToByteArray(String hexStr){
        //这里根据硬件统一编码
        return hexStr.getBytes();
    }
}
